Sieve
// :doObj('add,'Sieve)
// :doObj('build,'Sieve)
// :doObj('remove,'Sieve)
{
// ---------------------------------------------------------------------------------------
// Freeware...
//   The standard sieve benchmark for the Newton.
//   Info: Runs in about 143 seconds on my OMP.
//  Runs in about 65 seconds on my MP100.
//
//   Thanks to Steve Weyer for explaining a few things
//   and making some suggestions about the GoBtn object
//
// Ver 0.3 9/17/94 -RunNewt
// Ver 1.0 5/18/95 - Newt 3.0
// ---------------------------------------------------------------------------------------
	_proto: 'protoApp,
	title: "Sieve",
	ViewBounds: RelBounds(0,10,220,100),
	_package: {
		version: 100,
		copyright: ")1994,1995 S.Koren.  All rights reserved.", 
	icon: :GetIcon("Sieve"),
	devSignature: "SKoren",
},
	
}
-----
Sieve+about
{
		_proto: 'protoFloatNGo,
     viewBounds:RelBounds(5,5,200,90),
}

-----
Sieve+AboutBtn
{_proto: 'protoTextButton,
	text: "About...",
	viewBounds: RelBounds(5,5,60,16),
	buttonClickScript:func()
		about:open();
	
}

-----
Sieve+SStatus
{
		_proto: 'protoStaticText,
		viewBounds: RelBounds(20,30,200,16),
		text:  "Prime benchmark."
}

-----
Sieve+Status
{
		_proto: 'protoStaticText,
		viewBounds: RelBounds(20,50,200,16),
		text:  "Calculates primes from"
}

-----
Sieve+GoBtn
{
	_proto: 'protoTextButton,
	text: "Go...",
	viewBounds: RelBounds(150,5,60,16),
	buttonClickScript:func()
	begin
		SetValue(Status,'text ,  "");
		SetValue(EStatus,'text ,  "Please wait...");
		// SetValue will wait to display until end of buttonClickScript unless...
		RefreshViews(); // force screen update (use judiciously/minimally)
	    local  x, size, i, k, prime, count, iter, long ; 
		size := 8192;
		long := Ticks(); // start timer

		for iter := 1 to 10 do
		begin
			count := 0;
			x := NIL;  // to avoid memory problem of old&new arrays co-existing for a moment
			x := Array(size+1, 1); // reallocating (with new initial value) seems faster than recycling&filling
			for i := 1 to size do
				if x[i] = 1 then
				begin
					prime := i + i + 3;
					for k := (i+prime) to size by prime do
						x[k] := 0;
					count := count + 1;
				end;
		end;		

		SetValue(SStatus,'text ,"Start:" && long);  // NumberStr optional
		j := Ticks();
		i := (j-long) / 60;
		SetValue(Status,'text , "End  :" && j); 
		SetValue(EStatus,'text ,"Elap.:" && i && "sec.");
		:Notify(3,EnsureInternal("Sieve"), // avoid later "grip of death"
		    EnsureInternal("Num primes:" & count && "Time:" && i));
	end;
}


-----
Sieve+EStatus
{
		_proto: 'protoStaticText,
		viewBounds: RelBounds(20,70,200,16),
		text:  "1 to 8192, 10 times."
}


-----
Sieve.about+maboutText
{
// about text

	viewclass: 'clParagraphView,
	text: "by Serg Koren  \u000D\u " & Sieve._package.copyright & "  \u000D\u       SergK@eworld.com \u000D\u Freeware." ,
	viewFlags: 3,
	viewBounds: RelBounds(5,20,200,80),
}


-----
Sieve.about+title
{
// about title

	_proto: protoStaticText,
	viewBounds: RelBounds ( 20,5 ,150 ,16 ),
	// reformat version to x.xx in text
	text: "Sieve - Ver." &&  SubStr(NumberStr(Sieve._package.version),0,1) & "." & SubStr(NumberStr(Sieve._package.version),1,2),
}

-----
